<?php
import("mvc.Template");

class XMLTemplate extends Template {
	
	function XMLTemplate(&$registry) {
		Template::Template($registry);
	}
	
	function show($name) {
		
		if (isset($this->registry->vars[KEY_DOMXMLDOC])) {
			
			/*$xsl_file_name = SITE_PATH . 'WEB-INF'. DIRSEP .'templates' . DIRSEP . $name . '.xsl';
			if (file_exists($xsl_file_name) == false) {
				trigger_error ('Template `' . $name . '` does not exist.', E_USER_NOTICE);
				return false;
			}
			*/
			
			$xsl = $this->findByName($name);
			
			$params = array();
			//if (isset($_GET["titel"])) {
			//    $params["titel"] = $_GET["titel"];
			//}
	
			$result = $xsl->process($this->registry->vars[KEY_DOMXMLDOC]->dom, $params, false);
			print $result->dump_mem();
			
		} else {
			trigger_error ('Not found global XML file.', E_USER_NOTICE);
		}
	}
	
	function findByName($name) {
		$xsl_file_name = SITE_PATH . 'WEB-INF'. DIRSEP .'templates' . DIRSEP . $name . '.xsl';
		if (file_exists($xsl_file_name) == false) {
			trigger_error ('Template `' . $name . '` does not exist.', E_USER_NOTICE);
			return false;
		}
		
		return domxml_xslt_stylesheet_file($xsl_file_name);
	}
}
?>